home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / vbcc-68k-src / machines / amiga68k / libsrc / amigalib / rangerand.c < prev    next >
C/C++ Source or Header  |  1999-01-01  |  316b  |  19 lines

  1. #include <exec/types.h>
  2.  
  3. ULONG RangeSeed;
  4.  
  5. ULONG RangeRand(ULONG maxValue)
  6. { ULONG a=RangeSeed;
  7.   UWORD i=maxValue-1;
  8.   do
  9.   { ULONG b=a;
  10.     a<<=1;
  11.     if((LONG)b<=0)
  12.       a^=0x1d872b41;
  13.   }while((i>>=1));
  14.   RangeSeed=a;
  15.   if((UWORD)maxValue)
  16.     return (UWORD)((UWORD)a*(UWORD)maxValue>>16);
  17.   return (UWORD)a;
  18. }
  19.